<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");

if($act=='koukuan'){
	$msg='';
	if(trim($username)=='') $msg.="请输入会员名\\n";
	if(trim($ptype)=='') $msg.="请选择账户类型\\n";
	if(floatval($price)<=0) $msg.="请输入扣除的TXL个数\\n";
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	$sqlhy="select * from {$db_prefix}users where username='".trim($username)."'";
	$rshy=$db->get_one($sqlhy);
	if (!$rshy['id']) $msg.="会员不存在\\n";
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	//更新会员金额
	unset($dataArray);
    if ($ptype==1){
        $dataArray['price']=$rshy['price']-floatval($price);
        $e_type=3;
    }
    if ($ptype==2){
        $dataArray['sfprice']=$rshy['sfprice']-floatval($price);
        $e_type=3;
    }
    if ($ptype==3){
        $dataArray['znprice']=$rshy['znprice']-floatval($price);
        $e_type=3;
    }
    if ($ptype==4){
        $dataArray['slprice']=$rshy['slprice']-floatval($price);
        $e_type=3;
    }
    if ($ptype==5){
        $dataArray['jyprice']=$rshy['jyprice']-floatval($price);
        $e_type=3;
    }
    if ($ptype==6){
        $dataArray['gwprice']=$rshy['gwprice']-floatval($price);
        $e_type=3;
    }
    if ($ptype==7){
        $dataArray['djprice']=$rshy['djprice']-floatval($price);
        $e_type=3;
    }
	$condition="username='".trim($username)."'";
	$db->update("{$db_prefix}users",$dataArray,$condition);
	//财务记录
	$e_userid=$rshy['id'];$e_price=0-floatval($price);$e_ptype=$ptype;$e_addtime=$curtime;$e_memo=addslashes($memo);
	hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	//插入数据库
	unset($dataArray);
	$dataArray['username']=trim($username);
	$dataArray['price']=-$price;
	$dataArray['ptype']=$ptype;
	$dataArray['memo']=addslashes($memo);
	$dataArray['addtime']=$curtime;
	$db->insert("{$db_prefix}chongzhi",$dataArray);
	
	echo "<script>alert('扣款成功');location.href='chongzhi_lst.php';</script>";exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
.red{
	color:red;
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">扣款</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top">
		<form id="form1" name="form1" method="post" action="?act=koukuan">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td colspan="3"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;</td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td height="30" colspan="3">
			  
			  <table width="100%" height="120" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="30" align="center" bgcolor="#f2f2f2" class="left_txt">会员</td>
                  <td height="30" bgcolor="#f2f2f2" class="left_txt"><input name="username" type="text" id="username" />
                    <span class="red">                  * </span></td>
                </tr>
                <tr>
                  <td height="30" align="center" class="left_txt">账户类型</td>
                  <td height="30" class="left_txt"><label>
                    <select name="ptype" id="ptype">
					<option value="">请选择</option>
					<?
					foreach($hypricetypeary as $k1=>$v1){
						echo "<option value='{$k1}'>{$v1}</option>";
					}
					?>
                    </select>
                    <span class="red"> *</span></label></td>
                </tr>
                <tr>
                  <td height="30" align="center" class="left_txt">金额</td>
                  <td height="30" class="left_txt"><input name="price" type="text" id="price" size="10" />
TXL <span class="red"> *</span></td>
                </tr>
                <tr>
                  <td height="30" align="center" class="left_txt">说明</td>
                  <td height="30" class="left_txt"><label>
                    <textarea name="memo" cols="40" rows="6" id="memo"></textarea>
                  </label></td>
                  </tr>
              </table></td>
            </tr>
            
            <tr>
              <td height="30" colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td width="50%" height="30" align="right"><input type="submit" value="完成以上修改" name="B1" /></td>
              <td width="6%" height="30" align="right">&nbsp;</td>
              <td width="44%" height="30"><input type="reset" value="取消设置" name="B12" /></td>
            </tr>
            <tr>
              <td height="30" colspan="3">&nbsp;</td>
            </tr>
          </table>
		  </form>
		  </td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>
